# -*- coding: utf-8 -*-
'''
@author: olivia.dou
Created on: 2022/12/14 13:51
desc: 周边获客相关接口功能
'''

import requests
from . import url1,header2

"""https://qa.bank-app-svc.chinascope.net/surround/customer/nearby/app"""



def get_nearby_customers(location, **kwargs):
    """获取指定位置周边的企业信息

    :param location: 包含经纬度位置信息的字典 如{'latitude': 31.1023183, 'longitude': 121.5079867, 'altitude': 5e-324}
    :param kwargs:
    | page: 分页索引，默认1
    | size: 分页大小，默认20
    | region_codes: 区域编码列表
    | range: 范围大小，默认1(KM)
    | sorts: 排序规则， 默认： [{"sortField":"regStatus","sortOrder":"ASC"},{"sortField":"qual","sortOrder":"ASC"}]

    :return:
    """

    url = url1 + "/surround/customer/nearby/app"
    payload = {
        "page": kwargs['page'] if 'page' in kwargs else 1,
        "size": kwargs['size'] if 'size' in kwargs else 20,
        "lat": location['latitude'],
        "lng": location['longitude'],
        "regionCodes": kwargs['region_codes'] if 'region_codes' in kwargs else [],
        "range": kwargs['range'] if 'range' in kwargs else 1,
        "sorts": kwargs['sorts'] if 'sorts' in kwargs else [
            {
                "sortField": "regStatus",
                "sortOrder": "ASC"
            },
            {
                "sortField": "qual",
                "sortOrder": "ASC"
            }
        ]
    }

    res = requests.post(url, headers = header2, json = payload, verify=False)
    assert res.status_code==200,"获取周边企业失败：%s"%res.status_code
    return res.json()
